<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

	
	<div class="layui-row" id="editForm" style="display: none;">
		<form class="layui-form" action="" lay-filter="example">
			<div class="layui-form-item">
				<label class="layui-form-label">ID</label>
				<div class="layui-input-block">
					<input type="text" name="orderid" id="orderid" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">经办人</label>
				<div class="layui-input-block">
					<input type="text" name="empname" id="empname" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-block">
					<input type="text" name="username" id="username" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">房间号</label>
				<div class="layui-input-block">
					<input type="text" name="roomno" id="roomno" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
				</div>
			</div>

	<div class="layui-form-item">
    <label class="layui-form-label">订单状态</label>
    <div class="layui-input-block">
      <select name="orderstatus" lay-filter="aihao" id="orderstatus">
        <option value="0" id="zero">退房</option>
        <option value="1" id="one">入住</option>
        <option value="2" id="two">预定</option>
        <option value="3" id="three">订单取消</option>
      </select>
    </div>
  </div>
      <div class="layui-inline">
      <label class="layui-form-label">入住时间</label>
      <div class="layui-input-inline">
      <input type="text" name="orderstartdate" id="orderstartdate" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
<!--         <input type="text" class="layui-input" id="orderstartdate" name="orderstartdate" placeholder="yyyy-MM-dd"> -->
      </div>
    </div>
       <div class="layui-inline">
      <label class="layui-form-label">退房时间</label>
      <div class="layui-input-inline">
      <input type="text" name="orderenedate" id="orderenedate" lay-verify="title"
						autocomplete="off" placeholder="" class="layui-input" readonly="readonly" >
<!--         <input type="text" class="layui-input" id="orderenedate" name="orderenedate" placeholder="yyyy-MM-dd"> -->
      </div>
    </div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
				</div>
			</div>
		</form>
	</div>

	<div class="demoTable">
		订单号：
		<div class="layui-inline">
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		<button class="layui-btn" data-type="reload">搜索</button>
	</div>


	<table class="layui-hide" id="test" lay-filter="test"></table>



	<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		</script>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script src="layuiadmin/layui/layui.js"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<!-- <script type="text/javascript">
		layui.use('laydate', function my() {
			var laydate = layui.laydate;
			laydate.render({
				elem : '#orderstartdate'
			});
			laydate.render({
				elem : '#orderenedate'
			});
		});
	</script> -->

	<script>
		layui.use('table', function() {

			var table = layui.table;
			table.render({
				elem : '#test'
				//  ,url:'/test/table/demo1.json'
				,
				url : 'orderPage' //模拟接口
				,
				toolbar : '#toolbarDemo',
				title : '用户数据表',
				cols : [ [ {
					type : 'checkbox',
					fixed : 'left'
				}, {
					field : 'orderid',
					width : 100,
					title : '订单ID',
					sort : true
				}, {
					field : 'empname',
					width : 100,
					title : '经办员工',
				}, {
					field : 'username',
					width : 100,
					title : '用户名',
				}, {
					field : 'roomno',
					width : 100,
					title : '房间号',
					sort : true
				}, {
					field : 'orderdate',
					title : '下单时间',
					sort : true,
					width : 180
				}, {
					field : 'orderstartdate',
					width : 180,
					title : '入住时间',
					sort : true,

				}, {
					field : 'orderenedate',
					title : '退房时间',
					sort : true,
					width : 180
				}, {
					field : 'days',
					title : '入住天数',
					width : 90
				}, {
					field : 'salary',
					title : '价格',
					width : 90
				}, {
					field : 'orderstatus',
					title : '订单状态',
					width : 90,
					templet : function(res) {
						if (res.orderstatus == 0)
							return "退房";
						if (res.orderstatus == 1)
							return "入住";
						if (res.orderstatus == 2)
							return "预定";
						if (res.orderstatus == 3)
							return "订单取消";
					}
				}, {
					fixed : 'right',
					title : '操作',
					toolbar : '#barDemo',
					width : 150
				} ] ],
				page : true,
				id : 'testReload'
			});

			//头工具栏事件
			table.on('toolbar(test)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				//					switch(obj.event) {
				//						case 'getCheckData':
				//							var data = checkStatus.data;
				//							layer.alert(JSON.stringify(data));
				//							break;
				//						case 'getCheckLength':
				//							var data = checkStatus.data;
				//							layer.msg('选中了：' + data.length + ' 个');
				//							break;
				//						case 'isAll':
				//							layer.msg(checkStatus.isAll ? '全选' : '未全选');
				//							break;
				//					};
			});

			//监听行工具事件
			table.on('tool(test)', function(obj) {
				
				var data = obj.data;
				console.log(data);
				if (obj.event === 'edit') {
					$("#orderid").attr("value", data.orderid);
					$("#empname").attr("value", data.empname);
					$("#username").attr("value", data.username);
					$("#roomno").attr("value", data.roomno);
					$("#orderstartdate").attr("value", data.orderstartdate);
					$("#orderenedate").attr("value", data.orderenedate);
					if (data.orderstatus == 0) {
						$("#zero").attr("selected", true);
						$("#one").attr("selected", false);
						$("#two").attr("selected", false);
						$("#three").attr("selected", false);
					} else if(data.orderstatus == 1){
						$("#zero").attr("selected", false);
						$("#one").attr("selected", true);
						$("#two").attr("selected", false);
						$("#three").attr("selected", false);
					}else if(data.orderstatus == 2){
						$("#zero").attr("selected", false);
						$("#one").attr("selected", false);
						$("#two").attr("selected", true);
						$("#three").attr("selected", false);
					}else{
						$("#zero").attr("selected", false);
						$("#one").attr("selected", false);
						$("#two").attr("selected", false);
						$("#three").attr("selected", true);
					}


					var index1 = layer.open({
						title:"修改订单",
						skin:'layui-layer-rim',
						type : 1,
						content : $("#editForm"),
					});
					//只有加了这一句，表单的复选框，单选框才可以编辑
					layui.form.render();
					//监听提交
					layui.form.on('submit(demo1)', function(data2) {
						var d = data2.field;
						console.log(d)
						$.ajax({
							type : "get",
							url : "editOrder",
							data : d,
							success : function(data) {
								if (data.msg == "修改成功") {
									layer.msg(data.msg, {
										time : 1000
									}, function() {
										layer.close(index1);
										location.reload(); 
									});

								} else {
									layer.msg(data.msg)
								}
							}
						});

						return false;
					});
				}
			});

			//模糊查询
			var $ = layui.$, active = {
				reload : function() {
					var demoReload = $('#demoReload');

					//执行重载
					table.reload('testReload', {
						page : {
							curr : 1
						//重新从第 1 页开始
						},
						where : {
							
							content : demoReload.val(),

						}
					});
				}
			};

			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});
	</script>
</body>
</html>